<?php
namespace App\Dengje\Utils;

class Utils
{
    public function msectime()
    {
        list($tmp1, $tmp2) = explode(' ', microtime());
        return sprintf('%.0f', (floatval($tmp1) + floatval($tmp2)) * 1000);
    }
    /**
     * 生成编号
     * @param $type
     * @return string
     */
    public function getSn($type)
    {
        switch ($type) {
            case 1:         //订单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 2:         //支付单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 3:         //商品编号
                $str = 'G' . substr($this->msectime() . rand(0, 5), 1);
                break;
            case 4:         //货品编号
                $str = 'P' . substr($this->msectime() . rand(0, 5), 1);
                break;
            case 5:         //售后单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 6:         //退款单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 7:         //退货单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 8:         //发货单编号
                $str = $type . substr($this->msectime() . rand(0, 9), 1);
                break;
            case 9:         //提货单号
                $chars    = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '2', '3', '4', '5', '6', '7', '8', '9'];
                $charsLen = count($chars) - 1;
                shuffle($chars);
                $str = '';
                for ($i = 0; $i < 6; $i++) {
                    $str .= $chars[mt_rand(0, $charsLen)];
                }
                break;
            default:
                $str = substr($this->msectime() . rand(0, 9), 1);
        }
        return $str;
    }


}
